<template>
    <div class="page-store-platform-store-present bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="text-align: center; background: white; width: 2350px;"
                 :style="{width: urlParams.type === '1' ? '2350px' : '2000px'}">
                <div class="tr">
                    <div class="td text-center bold" style="width: 150px;">登录账号</div>
                    <div class="td text-center bold" style="width: 150px;" v-if="urlParams.type === '1'">客户类型</div>
                    <div class="td text-center bold" style="width: 150px;">编号</div>
                    <div class="td text-center bold" style="width: 150px;">名称</div>
                    <div class="td text-center bold" style="width: 150px;">唯一身份标识</div>
                    <div class="td text-center bold" style="width: 100px;">联系人</div>
                    <div class="td text-center bold" style="width: 100px;">联系电话</div>
                    <div class="td text-center bold" style="width: 200px;">地址</div>
                    <div class="td text-center bold" style="width: 200px;" v-if="urlParams.type === '1'">跟进人员</div>
                    <div class="td text-center bold" style="width: 200px;">付款方式</div>
                    <div class="td text-center bold" style="width: 100px;">状态</div>
                    <div class="td text-center bold" style="width: 100px;">显示顺序</div>
                    <div class="td text-center bold" style="width: 100px;">备注</div>
                    <div class="td text-center bold" style="width: 200px;">创建时间</div>
                    <div class="td text-center bold" style="width: 200px;">最后修改时间</div>
                    <div class="td text-center bold" style="width: 100px;">操作</div>
                </div>
                <div class="tr" v-for="(item, index)  in tbCommunityUserList" :key="item.id">
                    <div class="td text-center" style="width: 150px;">{{'item.sysUser.username' | toValue(item)}}</div>
                    <div class="td text-center" style="width: 150px;" v-if="urlParams.type === '1'">{{'item.tbCommunityUserType.name' | toValue(item)}}</div>
                    <div class="td text-center" style="width: 150px;">{{item.code}}</div>
                    <div class="td text-center" style="width: 150px;">{{item.name}}</div>
                    <div class="td text-center" style="width: 150px;">{{item.idCard}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.contact}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.phone}}</div>
                    <div class="td text-center" style="width: 200px;">{{item.address}}</div>
                    <div class="td text-center" style="width: 200px;" v-if="urlParams.type === '1'">{{item.communityUserIdsText}}</div>
                    <div class="td text-center" style="width: 200px;">{{item.payTypeText}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.statusText}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.displayOrder}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.remark}}</div>
                    <div class="td text-center" style="width: 200px;">{{item.createTime}}</div>
                    <div class="td text-center" style="width: 200px;">{{item.lastUpdateTime}}</div>
                    <div class="td text-center" style="width: 100px;">
                        <label style="margin-right: 15px; text-decoration: underline;"
                               @click="navigateTo(`/pages/sub/sub3-community-platform/community-platform/community-platform-community-user/community-platform-community-user-edit/index?type=${urlParams.type}`, null, item)">
                            编辑
                        </label>
                        <label style="text-decoration: underline;" @click="deleteItem(item, index)">
                            删除
                        </label>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 10px; padding-bottom: 10px;">
            <u-loadmore :status="pagination.status" bg-color="#eeeeee"/>
        </div>

        <div style="padding-bottom: 60px;"></div>

        <div class="custom-bottom-button">
            <label @click="navigateTo(`/pages/sub/sub3-community-platform/community-platform/community-platform-community-user/community-platform-community-user-add/index?type=${urlParams.type}`)">
                添加
            </label>
        </div>
    </div>
</template>

<script>
    import {CommonUtil} from "@/dev/core/utils/common.util";
    import {TbCommunityUserService} from "@/dev/services/tb-community-user.service";

    export default {
        data() {
            return {
                tbCommunityUserList: []
            }
        },
        onShow() {
            const _self = this;
            if (_self.urlParams.type === "0") {
                // 设置首页标题
                uni.setNavigationBarTitle({
                    title: '业务员列表'
                });
            } else if (_self.urlParams.type === "1") {
                // 设置首页标题
                uni.setNavigationBarTitle({
                    title: '客户列表'
                });
            }
            this.doRefresh(this.tbCommunityUserList);
        },
        // 上拉加载
        onReachBottom: function () {
            if (this.pagination.hasNextPage) {
                this.doInfinite()
            }
        },
        methods: {
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new TbCommunityUserService().findTableListCascade({
                    pagination: _self.pagination,
                    data: {
                        communityId: _self.globalVariable.userInfo.tbCommunity.id,
                        type: _self.urlParams.type
                    },
                }).then(result => {
                    _self.pagination.refreshPage(result);
                    _self.tbCommunityUserList = [..._self.tbCommunityUserList, ...result.list];
                });
            },
            /**
             * 删除规格
             * @param item
             * @param index
             */
            deleteItem(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbCommunityUserService().deleteTbCommunityUserByIds(item.id).then(result => {
                                _self.tbCommunityUserList.splice(index, 1);
                                _self.$forceUpdate();
                                CommonUtil.toast('删除成功');
                            });
                        }
                    }
                });
            }
        }
    }
</script>
